// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <memory>
#include <string>
#include <vector>
#include <thread>
#include <chrono>
#include <algorithm>
#include <paddle_inference_api.h>
#include <opencv2/opencv.hpp>

#include "base_util/utils.h"
#include "pdmodel_manager.h"

namespace paddle_infer {

class ImageBlob;

class SegPredictor {
public:
   SegPredictor(LogInfo *log_info);
   ~SegPredictor(){}

   int Run(cv::Mat& img, 
              std::vector<BaseInfoPD*> &det_infos, 
              PDModelManager *manager,
              int md_idx);
   
private:

   int RunSeg(std::vector<cv::Mat>& imgs, 
            std::vector<DetInfoPD> &det_infos, 
            PDModelManager *mng,
            int md_idx);

   int RunSeg(cv::Mat& img, 
            std::vector<BaseInfoPD*> &det_infos, 
            PDModelManager *mng,
            int md_idx);

   int output_poly(cv::Mat& label_mask, 
                  std::vector<BaseInfoPD*>& seg_infos, 
                  PDModelConfig* cfg);
   int output_mask(cv::Mat& img, 
                     float* p_out, int length,
                     ImageBlob* data_inputs, 
                     PDModelConfig *cfg,
                     std::vector<DetInfoPD> &det_infos);
private:
   LogInfo *log_ifo;
};
}  // namespace paddle_infer
